package com.ity.teamanagement.controller;

import com.ity.teamanagement.annocation.CheckAuthorityStatus;
import com.ity.teamanagement.entity.inputParam.*;
import com.ity.teamanagement.result.Result;
import com.ity.teamanagement.service.ArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author coderFu
 * @create 2021/11/10
 */
@RestController
@Api(tags = "文章模块")
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @ApiOperation("发布文章")
    @CheckAuthorityStatus
    @PostMapping("/addArticle")
    public Result addArticle(@RequestBody @Validated AddArticleParam addArticleParam){
        return articleService.addArticle(addArticleParam);
    }

    @ApiOperation("删除文章")
    @CheckAuthorityStatus
    @DeleteMapping("/deleteArticle")
    public Result deleteArticle(@RequestBody@Validated DeleteArticleParam deleteArticleParam){
        return articleService.deleteArticle(deleteArticleParam);
    }

    @ApiOperation("修改文章内容")
    @CheckAuthorityStatus
    @PutMapping("/updateArticle")
    public Result updateArticle(@RequestBody@Validated UpdateArticleParam updateArticleParam){
        return articleService.updateArticle(updateArticleParam);
    }

    @ApiOperation("根据模块id查询文章内容")
    @GetMapping("/getArticleByType")
    public Result getArticleByType(@PageableDefault(page = 1,size = 10)Pageable pageable,@Validated ArticleSelectParam articleSelectParam){
        return Result.success(articleService.getArticleByTypeForPages(pageable, articleSelectParam));
    }


    @ApiOperation("根据文章id查询文章详情")
    @GetMapping("/getArticleDetailsById")
    public Result getArticleDetailsById(@Validated SelectArticleParam selectArticleParam){
        return articleService.getArticleDetailsById(selectArticleParam);
    }

    @ApiOperation("获取文章类型信息")
    @GetMapping("/getArticleType")
    public Result getArticleType(){
        return articleService.getArticleType();
    }

}
